#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"

service-create-cmd() {
  #E create a $PLUGIN_COMMAND_PREFIX service named lolipop
  #E dokku $PLUGIN_COMMAND_PREFIX:create lolipop
  #E you can also specify the image and image version to use for the service.
  #E it *must* be compatible with the ${PLUGIN_IMAGE} image.
  #E export ${PLUGIN_DEFAULT_ALIAS}_IMAGE="${PLUGIN_IMAGE}"
  #E export ${PLUGIN_DEFAULT_ALIAS}_IMAGE_VERSION="${PLUGIN_IMAGE_VERSION}"
  #E dokku $PLUGIN_COMMAND_PREFIX:create lolipop
  #E you can also specify custom environment variables to start
  #E the ${PLUGIN_COMMAND_PREFIX} service in semi-colon separated form.
  #E export ${PLUGIN_DEFAULT_ALIAS}_CUSTOM_ENV="USER=alpha;HOST=beta"
  #E dokku $PLUGIN_COMMAND_PREFIX:create lolipop
  #A service, service to run command against
  #F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
  #F -i|--image IMAGE, the image name to start the service with
  #F -I|--image-version IMAGE_VERSION, the image version to start the service with
  #F -p|--password PASSWORD, override the user-level service password
  #F -r|--root-password PASSWORD, override the root-level service password
  declare desc="create a $PLUGIN_SERVICE service"
  local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@")
  [[ ${argv[0]} == "$cmd" ]] && shift 1
  declare SERVICE="$1" CREATE_FLAGS_LIST=("${@:2}")

  service_create "$SERVICE" "${@:2}"
}

service-create-cmd "$@"
